﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.IO;
using System.Windows.Media.Imaging;

namespace WcfClientGenerator.UI.Converters
{
    public class ConfigurationImageConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Uri uri = null;
            string file = value as string;
            
            if (!string.IsNullOrEmpty(file) && File.Exists(file))
                uri = new Uri(file, UriKind.Absolute);
            else
                uri = new Uri("pack://application:,,,/WcfClientGenerator.UI.v2;component/Images/default.png");

            BitmapImage imageSource = new BitmapImage(uri);
            return imageSource;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
